package com.pyue.eam.regi.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pyue.eam.admin.api.entity.regi.CqComplaintEntity;
import com.pyue.eam.common.core.util.R;
import com.pyue.eam.common.excel.annotation.ResponseExcel;
import com.pyue.eam.common.log.annotation.SysLog;
import com.pyue.eam.regi.service.CqComplaintService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客诉抱怨(0KM)
 *
 * @author lucc
 * @date 2023-10-12 20:38:25
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/cqComplaint" )
@Tag(description = "cqComplaint" , name = "客诉抱怨(0KM)管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class CqComplaintController {

    private final CqComplaintService cqComplaintService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param cqComplaint 客诉抱怨(0KM)
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    // @PreAuthorize("@pms.hasPermission('eam_cqComplaint_view')" )
    public R getCqComplaintPage(@ParameterObject Page page, @ParameterObject CqComplaintEntity cqComplaint) {
        LambdaQueryWrapper<CqComplaintEntity> wrapper = Wrappers.lambdaQuery();
        return R.ok(cqComplaintService.page(page, wrapper));
    }


    /**
     * 通过id查询客诉抱怨(0KM)
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    // @PreAuthorize("@pms.hasPermission('eam_cqComplaint_view')" )
    public R getById(@PathVariable("id" ) String id) {
        return R.ok(cqComplaintService.getById(id));
    }

    /**
     * 新增客诉抱怨(0KM)
     * @param cqComplaint 客诉抱怨(0KM)
     * @return R
     */
    @Operation(summary = "新增客诉抱怨(0KM)" , description = "新增客诉抱怨(0KM)" )
    @SysLog("新增客诉抱怨(0KM)" )
    @PostMapping
    // @PreAuthorize("@pms.hasPermission('eam_cqComplaint_add')" )
    public R save(@RequestBody CqComplaintEntity cqComplaint) {
        return R.ok(cqComplaintService.save(cqComplaint));
    }

    /**
     * 修改客诉抱怨(0KM)
     * @param cqComplaint 客诉抱怨(0KM)
     * @return R
     */
    @Operation(summary = "修改客诉抱怨(0KM)" , description = "修改客诉抱怨(0KM)" )
    @SysLog("修改客诉抱怨(0KM)" )
    @PutMapping
    // @PreAuthorize("@pms.hasPermission('eam_cqComplaint_edit')" )
    public R updateById(@RequestBody CqComplaintEntity cqComplaint) {
        return R.ok(cqComplaintService.updateById(cqComplaint));
    }

    /**
     * 通过id删除客诉抱怨(0KM)
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除客诉抱怨(0KM)" , description = "通过id删除客诉抱怨(0KM)" )
    @SysLog("通过id删除客诉抱怨(0KM)" )
    @DeleteMapping
    // @PreAuthorize("@pms.hasPermission('eam_cqComplaint_del')" )
    public R removeById(@RequestBody String[] ids) {
        return R.ok(cqComplaintService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param cqComplaint 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    // @PreAuthorize("@pms.hasPermission('eam_cqComplaint_export')" )
    public List<CqComplaintEntity> export(CqComplaintEntity cqComplaint,String[] ids) {
        return cqComplaintService.list(Wrappers.lambdaQuery(cqComplaint).in(ArrayUtil.isNotEmpty(ids), CqComplaintEntity::getId, ids));
    }
}
